package com.singlemusic.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpUtils;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.singlemusic.pojo.Songcomments;
import com.singlemusic.pojo.Songs;
import com.singlemusic.pojo.Users;
import com.singlemusic.service.impl.TestService;
import com.singlemusic.utils.AESUtils;
import com.singlemusic.utils.FileUtils;
import com.singlemusic.utils.MD5Utils;

@Controller
@RequestMapping("/test")
public class TestController {
	
	@Resource(name="testService")
	private TestService testService;
	
	@ResponseBody
	@RequestMapping("/loadUsers")
	public List<Users> testController(){
		List<Users> list = testService.getUserList();
		System.out.println(list.size());
		return list;
	}
	@RequestMapping("/addUsers")
	public String addUsers(){
		Users users = new Users();
		users.setUserid("user07");
		users.setUsername("user04");
		users.setUserpassword(MD5Utils.GetMD5Code("123456"));
		users.setUsersex("男");
		users.setRegdate("2016/10/3");
		
		testService.save(users);
		return "success";
	}
	@RequestMapping("/addComment")
	public String addComment(){
		Songcomments song = new Songcomments();
		
		Users user = testService.getUserList().get(0);
		Songs songs = testService.getSongList().get(0);
		song.setSongs(songs);
		song.setUsers(user);
		song.setCommentdate("2016/10/3");
		song.setCommentcontent("好听");
		song.setPopularitydegree(25);
		
		//testService.save(song);
		return "success";
	}
	
	@RequestMapping("/loadFile")
	public String loadFile(){
		return "success";
	}
	@RequestMapping("/loadPic")
	public String loadPic(HttpServletResponse response){
		FileUtils.loadFile("e:/test1.jpg", response);
		
		return null;
	}
}
